{include file="common/pc/header" title="微应用配置" /}

<style>
    #form {
        margin-top: 10px;
    }

    .one-line {
        height: 20px;
        text-overflow: ellipsis;
        white-space: nowrap;
        overflow: hidden;
    }
</style>

<div class="layui-collapse">
    <div class="layui-colla-item">
        <h2 class="layui-colla-title">全局微应用</h2>
        <div class="layui-colla-content">
            <form class="layui-form" action="" method="post" enctype="multipart/form-data" id="form">
                <div class="layui-form-item">
                    <label class="layui-form-label layui-form-label-long">ID</label>
                    <div class="layui-input-inline layui-input-inline-long">
                        <input type="text" autocomplete="off" class="layui-input readonly"
                               value="{$globalAgentId}"/>
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label layui-form-label-long">微应用名称</label>
                    <div class="layui-input-inline layui-input-inline-long">
                        <input type="text" autocomplete="off" class="layui-input" name="name"
                               value="{$globalMicroapp.name}"/>
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label layui-form-label-long">微应用Logo</label>
                    <div class="layui-input-inline layui-input-inline-long">
                        {d:up type="image" field="appIcon" value="$globalMicroapp.appIcon" btn="false"}浏览图片{/d:up}
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label layui-form-label-long">微应用描述</label>
                    <div class="layui-input-inline layui-input-inline-long">
                        <textarea class="layui-textarea" name="appDesc">{$globalMicroapp.appDesc}</textarea>
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label layui-form-label-long">后台地址</label>
                    <div class="layui-input-inline layui-input-inline-long">
                        <input type="text" name="ompLink" autocomplete="off" class="layui-input"
                               value="{$globalMicroapp.ompLink}">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label layui-form-label-long">前台地址(mobile)</label>
                    <div class="layui-input-inline layui-input-inline-long">
                        <input type="text" name="homepageLink" autocomplete="off" class="layui-input"
                               value="{$globalMicroapp.homepageLink}">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label layui-form-label-long">前台地址(PC)</label>
                    <div class="layui-input-inline layui-input-inline-long">
                        <input type="text" name="pcHomepageLink" autocomplete="off" class="layui-input"
                               value="{$globalMicroapp.pcHomepageLink}"/>
                    </div>
                </div>
                <div class="layui-form-item">
                    <div class="layui-input-block">
                        {if condition="$globalAgentId"}
                        <!-- 微应用已经存在 -->
                        <button class="layui-btn" lay-submit lay-filter="global-update" name="update">更新微应用</button>
                        <button class="layui-btn layui-btn-danger" lay-submit lay-filter="global-delete" name="delete">
                            删除微应用
                        </button>
                        {else/}
                        <!-- 微应用不存在 -->
                        <button class="layui-btn" lay-submit lay-filter="global-create" name="create">创建微应用</button>
                        {/if}
                    </div>
                </div>
            </form>
        </div>
    </div>
</div>

<div class="layui-collapse">
    <div class="layui-colla-item">
        <h2 class="layui-colla-title">所有自建微应用</h2>
        <div class="layui-colla-content layui-show">
            <table class="layui-table" id="microapps">
                <thead>
                <tr>
                    <th></th>
                    <th>ID</th>
                    <th>名称</th>
                    <th>logo</th>
                    <th>地址</th>
                </tr>
                </thead>
                <tbody>
                {volist name="microapps" id="microapp"}
                {if condition="$microapp['isSelf']"}
                <tr>
                    <td>
                        <button class="layui-btn layui-btn-danger layui-btn-sm"
                                onclick="delCustomMicroapp('{$microapp.agentId}','{$microapp.name}');">
                            删除
                        </button>
                    </td>
                    <td>
                        {$microapp.agentId}
                    </td>
                    <td title="{$globalMicroapp.appDesc}">
                        <div class="one-line">{$microapp.name}</div>
                        {if condition="$microapp['isSelf']"}
                        <span class="layui-badge layui-bg-blue">自建</span>
                        {/if}
                    </td>
                    <td>
                        <img src="{$microapp.appIcon}" style="width: 50px;"/>
                    </td>
                    <td>
                        {if condition="isset($microapp['ompLink']) && !empty($microapp['ompLink'])"}
                        <div class="one-line">后台地址：<a href="{$microapp.ompLink}" target="_blank">{$microapp.ompLink}</a>
                        </div>
                        {/if}
                        {if condition="isset($microapp['homepageLink']) && !empty($microapp['homepageLink'])"}
                        <div class="one-line">前台地址：<a href="{$microapp.homepageLink}" target="_blank">{$microapp.homepageLink}</a>
                        </div>
                        {/if}
                        {if condition="isset($microapp['pcHomepageLink']) && !empty($microapp['pcHomepageLink'])"}
                        <div class="one-line">前台地址(PC)：<a href="{$microapp.pcHomepageLink}" target="_blank">{$microapp.pcHomepageLink}</a>
                        </div>
                        {/if}
                    </td>
                </tr>
                {/if}
                {/volist}
                </tbody>
            </table>
        </div>
    </div>
</div>

<div class="layui-collapse">
    <div class="layui-colla-item">
        <h2 class="layui-colla-title">系统微应用</h2>
        <div class="layui-colla-content layui-show">
            <table class="layui-table">
                <thead>
                <tr>
                    <th>ID</th>
                    <th>名称</th>
                    <th>logo</th>
                    <th>地址</th>
                </tr>
                </thead>
                <tbody>
                {volist name="microapps" id="microapp"}
                {if condition="!$microapp['isSelf']"}
                <tr>
                    <td>
                        {$microapp.agentId}
                    </td>
                    <td title="{$globalMicroapp.appDesc}">
                        <div class="one-line">{$microapp.name}</div>
                    </td>
                    <td>
                        <img src="{$microapp.appIcon}" style="width: 50px;"/>
                    </td>
                    <td>
                        {if condition="isset($microapp['ompLink']) && !empty($microapp['ompLink'])"}
                        <div class="one-line">后台地址：<a href="{$microapp.ompLink}" target="_blank">{$microapp.ompLink}</a>
                        </div>
                        {/if}
                        {if condition="isset($microapp['homepageLink']) && !empty($microapp['homepageLink'])"}
                        <div class="one-line">前台地址：<a href="{$microapp.homepageLink}" target="_blank">{$microapp.homepageLink}</a>
                        </div>
                        {/if}
                        {if condition="isset($microapp['pcHomepageLink']) && !empty($microapp['pcHomepageLink'])"}
                        <div class="one-line">前台地址(PC)：<a href="{$microapp.pcHomepageLink}" target="_blank">{$microapp.pcHomepageLink}</a>
                        </div>
                        {/if}
                    </td>
                </tr>
                {/if}
                {/volist}
                </tbody>
            </table>
        </div>
    </div>
</div>


<script>
    layui.use(['form', 'element'], function () {
        var form = layui.form;
        //删除全局微应用
        form.on("submit(global-delete)", function (data) {
            layer.confirm("确认删除全局微应用？", function () {
                g.loading();
                $.post("delGlobalMicroapp?eid={$eid}", {_: new Date().getTime()}, function (ret) {
                    g.loading(false);
                    if (ret.code == 1) {
                        layer.msg("删除成功，页面跳转中...");
                        document.location.reload();
                    } else {
                        layer.alert(ret.msg);
                    }
                }, "json");
            });
            return false;
        });
        //创建全局微应用
        form.on("submit(global-create)", function (data) {
            g.loading();
            $.post("updateGlobalMicroapp?eid={$eid}", data.field, function (ret) {
                g.loading(false);
                if (ret.code == 1) {
                    layer.msg("创建成功，页面跳转中...");
                    document.location.reload();
                } else {
                    layer.alert(ret.msg);
                }
            }, "json");
            return false;
        });
        //更新全局微应用
        form.on("submit(global-update)", function (data) {
            g.loading();
            $.post("updateGlobalMicroapp?eid={$eid}", data.field, function (ret) {
                g.loading(false);
                if (ret.code == 1) {
                    layer.msg("更新成功，页面跳转中...");
                    document.location.reload();
                } else {
                    layer.alert(ret.msg);
                }
            }, "json");
            return false;
        });
    });

    /**
     * 删除微应用
     *
     * @param agentId
     * @param title
     */
    function delCustomMicroapp(agentId, title) {
        layer.confirm("确认删除微应用【" + title + "】？", function () {
            g.loading();
            $.post("delCustomMicroapp?eid={$eid}", {'agentId': agentId}, function (ret) {
                g.loading(false);
                if (ret.code == 1) {
                    layer.msg("删除成功，页面跳转中...");
                    document.location.reload();
                } else {
                    layer.alert(ret.msg);
                }
            }, "json");
        });
    }
</script>

{include file="common/pc/footer"/}